
////////////////////////////////////////////////////////////
//	File:		"AL_Task.h"
//	Author:		[AL] Anthony Lundquist
//	Created:	[AL] March 14, 2010
//	Purpose:	the base task class
////////////////////////////////////////////////////////////

#ifndef AL_TASK_H_
#define AL_TASK_H_

#include <vector>

class AL_Task
{

public:

	/* Public Data Members */

protected:

	/* Protected Data Members */
	void*	m_pTaskFunc;

	std::vector<std::pair<AL_Task*,int>>	m_vDependsOn;		// tasks we depend on
	std::vector<std::pair<AL_Task*,int>>	m_vDependencies;	// tasks that depend on us
	int										m_nNumDependencies;

private:

	/* Private Data Members */
	int		m_nType;

	/* Disabled Functions */

public:

	////////////////////////////////////////////////////////////
	//	Function:	RunTask
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Runs the specified task (called by the thread)
	//	In:			the time elapsed since last frame
	////////////////////////////////////////////////////////////
	void RunTask(float _fDelta);
	
	////////////////////////////////////////////////////////////
	//	Function:	FinishTask
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Lets all tasks dependant on this one know that
	//				it is done.
	////////////////////////////////////////////////////////////
	void FinishTask(void);
	
	////////////////////////////////////////////////////////////
	//	Function:	TryAddDependency
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Attempts to add a task that this task is
	//				dependant on.
	//	In:			the task that we attempt to add
	//	In:			the type of the task we are adding
	////////////////////////////////////////////////////////////
	virtual void TryAddDependency(AL_Task* _pDependency,int _nTaskType) = 0;

	////////////////////////////////////////////////////////////
	//	Function:	Constructor
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Initializes the object.
	//	In:			The task type
	////////////////////////////////////////////////////////////
	AL_Task(int _nTaskType);

	////////////////////////////////////////////////////////////
	//	Function:	Accessors
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Returns a specific data member.
	//	Out:		The data member.
	////////////////////////////////////////////////////////////
	inline int	GetTaskType(void)		{	return m_nType;	}
	bool		CheckIfCanRun(void);

	////////////////////////////////////////////////////////////
	//	Function:	Mutators
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Sets a specific data member.
	//	In:			The new value.
	////////////////////////////////////////////////////////////
	inline void SetTask(void* _pTask)	{	m_pTaskFunc = _pTask;	}

	////////////////////////////////////////////////////////////
	//	Function:	Destructor
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Deallocates the object.
	////////////////////////////////////////////////////////////
	virtual ~AL_Task();

protected:

	/* Protected Functions */
	////////////////////////////////////////////////////////////
	//	Function:	SetDependensy
	//	Created:	[AL] March 14, 2010
	//	Purpose:	Sets a task that this task depends on
	//	In:			The Task we depend on
	//	In:			the Task Type
	////////////////////////////////////////////////////////////
	void SetDependensy(AL_Task* _pDependency,int _nTaskType);

private:

	/* Private Functions */
	////////////////////////////////////////////////////////////
	//	Function:	DependensyFinished
	//	Created:	[AL] March 14, 2010
	//	Purpose:	The Tasks that we depend on will call this function
	//				when it is finished running
	//	In:			The Task we depend on
	////////////////////////////////////////////////////////////
	void DependensyFinished(AL_Task* _pTask);

};

#endif
